
var jxd_time=null;
var userInfo=null;
yanhx.addCommon("load",function(){
	$.java({
		action:"main.load",
		callback:function(data){
			$("#jxd_title").text("您好！"+data.name);
			userInfo=data;
			fillRoleAndCom();
		}
	});
	jxd_time=$("#jxd_time_span");
	window.setInterval(showTime,1000);
});
function fillRoleAndCom(){
	var roleSpan=$("#roleSpan");
	roleSpan.children(".form_list").list(userInfo.role,true);
	var comSpan=$("#comSpan");
	comSpan.children(".form_list").list(userInfo.com,true);
	roleSpan.children(".checkItem").text(roleSpan.children(".form_list")
	.children("#l_"+userInfo.curRole).text());
	comSpan.children(".checkItem").text(comSpan.children(".form_list")
	.children("#l_"+userInfo.curCom).text());
}
function showTime(){
	var d=new Date();
	jxd_time.text(d.toDateString());
}
yanhx.addFunc("changeRole",function(){
	var src=$src();
	if(src.attr("id")==("l_"+userInfo.curRole)){
		src.parent().hide();
	}
	else{
		$.java({
			action:"main.changeRole",
			param:{role_id:src.attr("id").replace("l_","")},
			callback:function(data){
				
			}
		});
	}
});
yanhx.addFunc("changeCom",function(){
	var src=$src();
	if(src.attr("id")==("l_"+userInfo.curCom)){
		src.parent().hide();
	}
	else{
		$.java({
			action:"main.changeCom",
			param:{role_id:src.attr("id").replace("l_","")},
			callback:function(data){
				
			}
		});
	}
});


yanhx.addFunc("openTreeTab",function(){
	
});
yanhx.addFunc("fillTreeItem",function(){
	var data=this.getData(this.curRow);
	this.curRow.bind("click",function(e){
		var src=$src();
		if(!src.hasClass("treeText"))
			return;
		src.attr("id","tree_"+data.id);
		yanhx.exec("stopEvent",e);
		if(data.path){
			top.yanhx.exec("tabHandle.open",{
				tabKey:"tab_"+data.id,
				tabName:data.name,
				tabSrc:data.path
			});
		}else{
			$(this).children(".tree_ctrl").trigger("click");
		}
	});
	//默认打开首页
	if(data.id=="1"){
		top.yanhx.exec("tabHandle.open",{
			tabKey:"tab_"+data.id,
			tabName:data.name,
			tabSrc:data.path
		});
	}
});
yanhx.addFunc("resizeTab",function(){
	var tab=$("#jxdTab");
	var tree=tab.children(".treeTd");
	var tabTd=tab.children(".tabTd");
	if(this.hasClass("show")){
		this.removeClass().addClass("showRight");
		tree.addClass("hideTree");
		tabTd.addClass("fullWidth");
	}else{
		this.removeClass().addClass("show").addClass("showLeft");
		tree.removeClass("hideTree");
		tabTd.removeClass("fullWidth");
	}
});
function queryMenu(p){
	$.java({
		action:"main.queryMenu",
		param:{parent:p.id},
		callback:function(data){
			treeHandle.exec($("#jxdTab").find("#menuTree"),"bindData",data);
		}
	});
};
yanhx.addCommon("load",function(){
	var tab=$("#jxdTab");
	var menuTree=tab.find("#menuTree");
	menuTree.listTree({
		fillItem:yanhx.findFunc("fillTreeItem"),		
		hasSub:function(){return true},
		bindQry:queryMenu
	});
	queryMenu({id:0});
	yanhx.exec("tabHandle.init",{
		tool:tab.find("#menuTab"),
		content:tab.find("#menuFrame"),
		max:8
	});
});


var newsDiv=null;
yanhx.addCommon("load",function(){
	//查询当天未读信息
	newsDiv=$("#jxd_news");
	queryNewsTotal();
	queryNews({page:1,pageSize:10});
	newsDiv.warnPanel();
	newsDiv.show("slow");
});
function queryNewsTotal(){
	$.java({
		action:"main.newsTotal",
		callback:function(data){
			newsDiv.find("#totalSpan").text(data.total);
		}
	});
};
function queryNews(param){
	$.java({
		action:"main.news",
		param:param,
		callback:function(data){
			if(!data.length){
				newsDiv.find("button").removeAttr("page").hide();
				return;
			}
			newsDiv.find("div.form_list").list(data,false,{
				noTitle:true
			});
		}
	});
};
yanhx.addFunc("closeNews",function(){
	$("#jxd_news").remove();
});
yanhx.addFunc("qryMoreNews",function(){
	var p=this.attr("page");
	if(p){
		p=Number(p)+1;
		this.attr("page",p);
		queryNews({page:p,pageSize:10});
	}
});
